import cv2
import re

picture_path = 'picture/'


# 功能：实现图片缩放
# path：文件名字  high：图片高度  wide：图片宽度
# return：处理后的图片路径
def reduce_imageSize(path, high, wide):
    # 读取图片
    image = cv2.imread(picture_path + path)

    # 图片缩放
    image1 = cv2.resize(image, (wide, high))

    # 确定修改后的文件名
    suffix_name = re.sub(r'[.](?=(xbm|tif|pjp|svgz|jpg|jpeg|ico|tiff|gif|svg|jfif|webp|png|bmp|pjpeg|avif)$)', "_ri.",
                         path, re.I)

    # 保存图片
    cv_write(picture_path + suffix_name, image1)

    return suffix_name

    # 图片显示
    # cv2.imshow("resize", image1)
    # cv2.imshow("image", image)
    # cv_show()


# 功能：图片保存
def cv_write(name, img):
    cv2.imwrite(name, img)


# 功能：图像显示等待函数
def cv_show():
    cv2.waitKey(0)
    cv2.destroyAllWindows()
